package com.zhangtao.demo.common.vo;

import java.util.UUID;

import com.zhangtao.demo.common.enums.ResultStatus;

/**
 * @ClassName: JsonResponseEntity.java
 * @Description: TODO(用一句话描述该文件做什么)
 * @author 张涛
 * @version V1.0
 * @Date 2018年11月13日 下午12:58:15
 */
public class JsonResponseEntity<T> {
	private String code;
	private String req_id;
	private String msg;
	private T data;

	/**
	 *
	 * @Title: newJsonResult
	 * @Description: 传递状态枚举类型和数据
	 * @param: @param result
	 * @param: @param data
	 * @param: @return
	 * @return: JsonResponseEntity<Object>
	 * @throws @author 张涛
	 * @Date 2017年12月26日 下午1:51:34
	 */
	public static JsonResponseEntity<Object> newJsonResult(ResultStatus result, Object data) {
		return new JsonResponseEntity<>(result, data);
	}

	/**
	 *
	 * @Title: newJsonResult
	 * @Description: 传递状态枚举类型和自定义提示信息
	 * @param: @param result
	 * @param: @param data
	 * @param: @return
	 * @return: JsonResponseEntity<Object>
	 * @throws @author 张涛
	 * @Date 2017年12月26日 下午1:51:34
	 */
	public static JsonResponseEntity<Object> newJsonResultWithMsg(ResultStatus result, String msg) {
		return new JsonResponseEntity<>(result.getCode(), msg, "");
	}

	public static JsonResponseEntity<Object> newJsonResultWithMsgAndData(ResultStatus result, String msg, Object data) {
		return new JsonResponseEntity<>(result.getCode(), msg, data);
	}

	/**
	 *
	 * @Title: newJsonResult
	 * @Description: 直接指定状态值，不设置数据
	 * @param: @param result
	 * @param: @return
	 * @return: JsonResponseEntity<Object>
	 * @throws @author 张涛
	 * @Date 2017年12月26日 下午1:51:05
	 */
	public static JsonResponseEntity<Object> newJsonResult(ResultStatus result) {
		return new JsonResponseEntity<>(result, "");
	}

	/**
	 *
	 * @Title: newJsonResult
	 * @Description: 只传数据的自动设置为成功的状态码，并将数据赋值到data
	 * @param: @param data
	 * @param: @return
	 * @return: JsonResponseEntity<Object>
	 * @throws @author 张涛
	 * @Date 2017年12月26日 下午1:50:32
	 */
	public static JsonResponseEntity<Object> newSuccessJsonResult(Object data) {
		return new JsonResponseEntity<>(ResultStatus.SUCCESS, data);
	}

	public JsonResponseEntity() {
		super();
	}

	public JsonResponseEntity(String code, String msg) {
		super();
		this.req_id = UUID.randomUUID().toString();
		this.code = code;
		this.msg = msg;
		this.data = null;
	}

	public JsonResponseEntity(String code, String msg, T data) {
		super();
		this.req_id = UUID.randomUUID().toString();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public JsonResponseEntity(ResultStatus result, T data, String req_id) {
		super();
		this.req_id = req_id;
		this.code = result.getCode();
		this.msg = result.getDescription();
		this.data = data;
	}

	public JsonResponseEntity(ResultStatus result, T data) {
		super();
		this.req_id = UUID.randomUUID().toString();
		this.code = result.getCode();
		this.msg = result.getDescription();
		this.data = data;
	}

	public void setAvnResultStatus(ResultStatus result) {
		this.code = result.getCode();
		this.msg = result.getDescription();
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getReq_id() {
		return req_id;
	}

	public void setReq_id(String req_id) {
		this.req_id = req_id;
	}
}
